package org.thirdHero.core.util;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResponseUtil<T extends Serializable> {
    private T t;
    public static Object ok() {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 1);
        obj.put("errmsg", "成功");
        return obj;
    }

    public static Object ok(Object data) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 1);
        obj.put("errmsg", "成功");
        obj.put("data", data);
        return obj;
    }


    public static Object ok(List<String> keys,List<Object> args){
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 1);
        obj.put("errmsg", "成功");
        for(int i =0 ;i < args.size();i++){
            obj.put(keys.get(i),args.get(i));
        }
        return obj;
    }
    public static Object ok(String errmsg,List<String> keys,List<Object> args){
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 1);
        obj.put("errmsg", errmsg);
        for(int i =0 ;i < args.size();i++){
            obj.put(keys.get(i),args.get(i));
        }
        return obj;
    }

    public static Object ok(String errmsg, Object data) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 1);
        obj.put("errmsg", errmsg);
        obj.put("data", data);
        return obj;
    }

    public static Object ok(int code, String message) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", code);
        obj.put("errmsg", message);
        return obj;
    }


    public Object ok(String errorMsg, int total, List<T> t){
        return commListOk(errorMsg, total, (List<T>) t);
    }
    public Object ok(String errorMsg, long total, List<T> t){
        return commListOk(errorMsg, total, (List<T>) t);
    }

    private Object commListOk(String errorMsg, long total, List<T> t) {
        Map<String, Object> obj = new HashMap<String, Object>();
        HashMap<String,Object> data = new HashMap<>();
        obj.put("errno", 1);
        obj.put("errmsg", errorMsg);
        data.put("total",total);
        data.put("items",t);
        obj.put("data",data);
        return obj;
    }

    public static Object fail() {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", -1);
        obj.put("errmsg", "错误");
        return obj;
    }
    public static Object fail(String errmsg){
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", -1);
        obj.put("errmsg", errmsg);
        return obj;
    }
    public static Object fail(int errno, String errmsg) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", errno);
        obj.put("errmsg", errmsg);
        obj.put("data",errmsg);
        return obj;
    }
    public static Object errorBussiness(String errormsg) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", -1);
        obj.put("errmsg", "错误");
        obj.put("data",errormsg);
        return obj;
    }


    public static Object fail401() {
        return fail(401, "请登录");
    }

    public static Object unlogin(){
        return fail401();
    }

    public static Object fail402() {
        return fail(402, "参数不对");
    }

    public static Object badArgument(){
        return fail402();
    }
    public static Object noPower(){
        return fail(408,"权限不足");
    }
    public static Object fail403() {
        return fail(403, "参数值不对");
    }

    public static Object badArgumentValue(){
        return fail403();
    }

    public static Object fail501() {
        return fail(501, "业务不支持");
    }

    public static Object unsupport(){
        return fail501();
    }

    public static Object fail502() {
        return fail(502, "系统内部错误");
    }

    public static Object serious(){
        return fail502();
    }

    public static Object failLogin( ){return fail(-1,"帐号或密码不正确");}

    public static Object failWxLogin(){return fail(-1,"用户未注册");};


    public static Object failEmptySpecifications(){ return fail(10000,"商品规格不存在，请添加商品的规格");}


}

